home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / rexx / SuperEval.lha / SuperEval / Eval.rexx next >
OS/2 REXX Batch file  |  1998-04-27  |  4KB  |  99 lines

  1. /****
  2. *   Enhanced "c:Eval" Command
  3. *
  4. *   With trig and other functions
  5. *   see REXXMATHLIB.library for fuction details
  6. *
  7. *   syntax is the same as the rexxmathlib function calls
  8. *              ie: func(x[,y])
  9. *          OR spaces may be used as deliminators (in all funtions)
  10. *              ie: func x [y]
  11. *
  12. *   There are two extra functions:
  13. *
  14. *   1)   DEG(deg,min,sec) outputs Decimal degrees
  15. *     or the alternative syntax is DEG(dd.mmss)
  16. *
  17. *   2)   DMS(DD.dddd) outputs dd mm ss
  18. *
  19. *
  20. *   If the function is unknown to rexxmathlib then the original line is
  21. *      passed, as typed, to the c:eval function. This alows for all the
  22. *      original "eval" maths (and syntax) to be used as a failsafe.
  23. *
  24. *
  25. *   Add the line
  26. *         Alias  Eval  rx rexx:eval.rexx []
  27. *                 into the s:shell-startup script and use in any Shell
  28. *                 syntax:  eval func(x[,y])  OR as per dos EVAL command
  29. *   Put eval.rexx into rexx:
  30. *   and rexxmathlib.library into libs:
  31. *
  32. *     NOTE: all angles are input as decimal DEGREES    (NOT radians)
  33. **/
  34. call addlib('rexxmathlib.library',0,-30)
  35.  
  36. numeric digits 14                 /* use the maximum */
  37. conversion = 0.017453292519943    /* (2 * PI)/360 ; 360deg = 2 pi radians */
  38.                                   /* conversion = 1 to use radians */
  39.  
  40. signal on error                   /* use ERROR and SYNTAX to pass control to c:eval */
  41. signal on syntax
  42.  
  43. parse upper arg RawInput                       /* accept a wide range of input styles */
  44.    StdInput = translate(RawInput,'   ','(,)')  /* replace separators with blanks */
  45.    parse var StdInput Function xx yy zz .      /* BLANKS are our "DESIGN" seperator */
  46.  
  47. Func = left(Function,3)                        /* change input degrees to radians for trig functions */
  48. if (Func='COS')|(Func='SIN')|(Func='TAN') then xx = xx * conversion
  49. if Func = 'LOG' then Function = 'LOG10'        /* use Log as base10 log function name */
  50.  
  51. if (yy ~= '') then do
  52.    if Func = 'DEG' then do                     /* allows 1 digit input by correcting to two digit leading zero ie: dd.mmss (decimal seconds are allowed */
  53.       yy = right(yy,2,0)
  54.       if index(zz,'.') ~= 3 then zz = right(zz,length(zz)+1,0)
  55.       operand = xx'.'yy || zz
  56.    end
  57.    else operand = xx','yy                      /* two part operand, comma seperated */
  58. end
  59. else operand = xx
  60.  
  61. interpret Value '=' Function'('Operand')'      /* generic and all purpose function call */
  62.  
  63. Func = left(Function,4)                        /* correct output radians to degrees in Arc Trig functions*/
  64. if (Func='ACOS')|(Func='ASIN')|(Func='ATAN') then Value = Value/Conversion
  65.  
  66. echo ' => 'Value '0a'x                         /* our answer */
  67.  
  68. exit                                           /* normal end program */
  69.  
  70.  
  71.  
  72.  
  73. error:                                         /* if all else fails */
  74. syntax:                                        /* or non_rexxmath.library problem */
  75.  
  76.    address command 'eval' RawInput 'lformat = " => %N *N"'
  77.  
  78. exit                                           /* and quit */
  79.  
  80.  
  81. DEG: procedure                                 /* convert Deg Min Sec to decimal degrees */
  82.  parse arg Deg '.' Min +2 Sec
  83. return Deg + Min/60 + Sec/3600
  84.  
  85.  
  86. DMS: procedure                                 /* convert decimal degs to Degs Min Sec */
  87.  parse upper arg Deg
  88.  cut = index(Deg,'.')
  89.  parse arg Deg =cut MinSec
  90.  
  91.  Min = MinSec * 60
  92.  cut = index(Min,'.')
  93.  parse var Min Min =cut Sec
  94.  
  95. return Deg Min Sec*60
  96.  
  97. exit                                           /* end script eval.rexx */
  98.  
  99.